package com.cskaoyan.service.wx;

import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.MarketBrand;
import com.cskaoyan.bean.wx.brand.WxBrandListListVO;
import com.cskaoyan.bean.wx.brand.WxBrandListVO;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.cskaoyan.mapper.wx.WxBrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenai
 * @description TODO
 * @date 2022-06-08 17:10
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    WxBrandMapper wxBrandMapper;
    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Override
    public WxBrandListVO list(BaseParam baseParam) {
        PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());
        List<WxBrandListListVO> list = new ArrayList<>();
        list = wxBrandMapper.list();
        PageInfo pageInfo = new PageInfo(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return new WxBrandListVO(baseParam.getPage(), baseParam.getLimit(), total, pages, list);
    }

    @Override
    public MarketBrand detail(Integer id) {
        return marketBrandMapper.selectByPrimaryKey(id);
    }
}
